1 哪些方法可以用

在翻看了众多页面之后,可以列出一些可以尝试的点:

1.1 直接打开URL window.open

1.2 HTML5 A 标签 的download属性

可以如下实现

<a href="/url/to/file/path" download="downloadName">点击下载</a>

1.3 使用封装的JavaScript库

2 参考资料

  1. Save/download data generated in JavaScript
  2. JavaScript Local I/O tests
  3. Force Download an Image Using Javascript
  4. How to trigger a file download when clicking an html button or javascript
  5. Using HTML5/Javascript to generate and save a file
  6. 在浏览器端用JS创建和下载文件
  7. JavaScript多文件下载
  8. JavaScript多文件下载
  9. Starting file download with Javascript
  10. 什么是data URI scheme及如何使用data URI scheme
  11. Data URI和MHTML完整解决所有浏览器
  12. DataURL在Web浏览器中的兼容性总结
  13. Download data url file
  14. JS魔法堂:Data URI Scheme介绍
  15. How to write a file / give it to the user
  16. HTML5 Cross Browser Polyfills
  17. How to force save as dialog box in firefox besides changing headers?
  18. Better approach to download file in JavaScript
  19. Does execCommand SaveAs work in Firefox?
  20. Saving generated files on the client-side
  21. Save to Drive Button
  22. 通过js保存图片到本地

2.1 HTTP Content Disposition

  1. Content-Disposition header - forcing SaveAs in browsers
  2. Content-Disposition

2.2 HTML5 A 标签

  1. W3C HTML5 A
  2. HTML: The Living Standard
  3. HTML5 download attribute with JavaScript
  4. Better approach to download file in JavaScript
  5. Save files on disk using JavaScript
  6. Downloading resources in HTML5
  7. 变通方法实现保存文件

2.3 下载库参考 HTML5

  1. Blob.js
  2. canvas-toBlob.js
  3. FileServer.js
  4. Downloadify
  5. Downloadify Example
  6. jquery.fileDownload
  7. jQuery File Download Plugin for Ajax
× 赞赏这个人~
打赏二维码